package com.itheima.springbootsecurity.mapper;

import com.itheima.springbootsecurity.domain.Resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 资源表 Mapper 接口
 * </p>
 *
 * @author faithwu
 * @since 2024-07-12
 */
@Mapper
public interface ResourceMapper extends BaseMapper<Resource> {

    @Select("SELECT DISTINCT r.`path` FROM resource r \n" +
            "LEFT JOIN role_resource rr ON rr.resource_id  = r.id \n" +
            "LEFT JOIN `role` r2 ON r2.id = rr.role_id \n" +
            "LEFT JOIN role_user ru on ru.role_id = r2.id \n" +
            "LEFT JOIN `user` u ON u.id = ru.user_id \n" +
            "WHERE u.id = #{userId}")
    List<String> getPathListByUserid(Integer userId);
}
